const merge = require('webpack-merge');
const common = require('./webpack.base.js');
const webpack =require('webpack');
const path = require('path');
function resolve (dir) {
  return path.join(__dirname, '..', dir)
}
const config =require('./config.js');
// 将 Hol-reload 热重载的客户端代码添加到 webpack.base.conf 的 对应 entry 中，一起打包
Object.keys(common.entry).forEach(function (name) {
  common.entry[name] = ['./config/dev-client'].concat(common.entry[name])
})
const webpackconfig = merge(common, {
    mode: 'development',
    // 最新的配置为 cheap-module-eval-source-map，虽然 cheap-module-eval-source-map更快，但它的定位不准确
    //devtool: '#cheap-module-eval-source-map',
    devtool: false ,
    module:{
      rules:[
        {
          test:/\.vue$/,
          loader:'vue-loader',
          include: [resolve('src'),resolve('ui')],
     			exclude: /node_modules/,
          options:{
            cacheDirectory: true,
            hotReload: true, // 热重载	
            loaders:{
              css:'vue-style-loader!css-loader',
              less:'vue-style-loader!css-loader!less-loader'
            }
          }
        },{
          test:/\.(less|css)$/,
          include: [resolve('src'),resolve('ui')],
     			exclude: /node_modules/,
          use:[
              'style-loader','css-loader','less-loader'
          ]
        }
      ]
    },
    output: {
	    path: config.dev.assetsSubPath,
		  filename:config.dev.filename,
		  publicPath:config.dev.assetsPublicPath,//解析目录相对于Html引用
	  },
    devServer: { // 开发服务器
        contentBase:path.resolve(__dirname,'dist'),
        port:config.dev.port,
        //compress: true,//使用gzip
        before:function(app){
            app.get("/api/list",function(req,res){
              res.json({data:[{name:'stear'},{name:'cc'}]})
            })
        },
        hot: true,
        open:true,
        proxy: config.dev.proxy
    },
    plugins:[
      new webpack.DefinePlugin({
        'process.env': require('./config.dev.js')
      }),
    ]
  
});
module.exports=webpackconfig;